package com.sinvo.oa.exception;

import com.sinvo.oa.result.ResultCode;
import lombok.Data;

/**
 * @Description 自定义异常类
 */
@Data
public class CustomException extends RuntimeException {
    private Integer code;

    private String message;

    /**
     * 通过自定义状态码和错误消息创建异常对象
     *
     * @param code
     * @param message
     */
    public CustomException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 通过枚举类型对象创建异常对象
     *
     * @param resultCode
     */
    public CustomException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + this.getCode() +
                ", message=" + this.getMessage() +
                '}';
    }
}
